home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / sllistb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.8 KB  |  107 lines

  1. // ----------------------------------------------------------- // 
  2. // ------------------------------- //
  3. // -------- Start of File -------- //
  4. // ------------------------------- //
  5. // ----------------------------------------------------------- //
  6. // C++ Header File Name: sllistb.h 
  7. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  8. // Produced By: Doug Gaer
  9. // File Creation Date: 12/29/1996
  10. // Date Last Modified: 03/15/1999
  11. // Copyright (c) 1997 Douglas M. Gaer
  12. // ----------------------------------------------------------- // 
  13. // ---------- Include File Description and Details  ---------- // 
  14. // ----------------------------------------------------------- // 
  15. /*
  16. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  17. All those who put this code or its derivatives in a commercial
  18. product MUST mention this copyright in their documentation for
  19. users of the products in which this code or its derivative
  20. classes are used. Otherwise, you have the freedom to redistribute
  21. verbatim copies of this source code, adapt it to your specific
  22. needs, or improve the code and release your improvements to the
  23. public provided that the modified files carry prominent notices
  24. stating that you changed the files and the date of any change.
  25.  
  26. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  27. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  28. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  29. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  30. CORRECTION.
  31.  
  32. Base classes for singly linked list implementations. The
  33. SNodeBase class and the SDLListBase class separates the
  34. nodes from the data stored in the list by storing pointers
  35. to the data. Classes derived from these base classes can
  36. deal with any type of node data.
  37.  
  38. Changes:
  39. ================================================================
  40. 03/02/1999: Changed GetHeader(), GetFront(), and GetBack() functions
  41. from protected to public access. 
  42. Changed by: Doug Gaer
  43. */
  44. // ----------------------------------------------------------- //   
  45. #ifndef __SLLISTB_HPP
  46. #define __SLLISTB_HPP
  47.  
  48. // (S)ingly Linked List (N)ode (B)ase class 
  49. class SNodeBase
  50. {
  51. protected:
  52.   friend class SLListBase;
  53.  
  54. protected:
  55.   void InsertAfter(SNodeBase *Node);
  56.   SNodeBase *RmvNext();
  57.   void SelfRef() { Next = this; }
  58.  
  59. protected:
  60.   SNodeBase *Next;
  61. };
  62.  
  63. // (S)ingly (L)inked (L)ist (B)ase class 
  64. class SLListBase : public SNodeBase
  65. {
  66. protected:
  67.   SLListBase() { MakeEmpty(); }
  68.   virtual ~SLListBase();
  69.  
  70. public:
  71.   virtual void Clear();
  72.   int IsEmpty() const { return (const SNodeBase *)Next == this; }
  73.   int IsHeader(const SNodeBase *Node) const { return Node == this; }
  74.   SNodeBase *GetHeader() { return this; }
  75.   const SNodeBase *GetHeader() const { return this; }
  76.   SNodeBase *GetFront() { return Next; }
  77.   const SNodeBase *GetFront() const { return Next; }
  78.   SNodeBase *GetBack() { return Back; }
  79.   const SNodeBase *GetBack() const { return Back; }
  80.  
  81. protected:
  82.   virtual SNodeBase *DupNode(const SNodeBase *Node) = 0;
  83.   virtual void FreeNode(SNodeBase *Node) = 0;
  84.   virtual void MakeEmpty();
  85.  
  86.   void InsertAfter(SNodeBase *A, SNodeBase *B) {
  87.     A->InsertAfter(B);
  88.     if(A == Back) Back = B;
  89.   }
  90.  
  91.   void AttachToFront(SNodeBase *Node) { InsertAfter(this, Node); }
  92.   void AttachToBack(SNodeBase *Node) { InsertAfter(Back, Node); }
  93.   SNodeBase *RmvNext(SNodeBase *Node);
  94.   SNodeBase *RmvFront() { return RmvNext(this); } // Does not delete node
  95.   int Copy(const SLListBase &List);
  96.   int Cat(const SLListBase &List);
  97.  
  98. protected:
  99.   SNodeBase *Back;
  100. };
  101.  
  102. #endif  // __SLLISTB_HPP //
  103. // ----------------------------------------------------------- //
  104. // ------------------------------- //
  105. // --------- End of File --------- //
  106. // ------------------------------- //
  107.